<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="com.sinodata.bsm.center.purview.FunctionConstants"%>
<%@page import="com.sinodata.bsm.center.purview.UserFunctionValidate"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>event-rule-common</title>
    
	<%@ include file="../include/common.jsp"%>
	<%@ include file="../include/jbox.jsp"%>
	<%@ include file="../include/table.jsp"%>
	
	<script type="text/javascript">
	function datagrid(){
		var oTable=	$('#depmtList').dataTable();
		 oTable._fnAjaxUpdate();
	}

	$(function(){
		//加载grid
		
		var oTable=	$('#depmtList').dataTable({
			"bProcessing": true, 
			"bServerSide": true,
			"sServerMethod": 'POST',
			"sAjaxSource":'${pageContext.request.contextPath}/notify/notify-rule!list.action?resId='+'${resId}',
			"bPaginate": false,
			"bSort": true,
			"bFilter":false,
			"bJQueryUI":false,
			"sPaginationType": "full_numbers",
			"sDom":'rt<flp>',
			"aoColumns":[
				<%if(UserFunctionValidate.sysFunctionValidate(FunctionConstants.SYSTEM_MANAGER)){%>
				{"mDataProp":"op","":"center","bSortable": false},
				<%}%>
				{"mDataProp":"name","bSortable": false},
				{"mDataProp":"resName","bSortable": false},
				{"mDataProp":"eventLevels","bSortable": false},
				{"mDataProp":"status","bSortable": false},
				{"mDataProp":"isExclude","bSortable": false,"fnCreatedCell":function(nTd, sData, oData, iRow, iCol){
				    var html = "";
				    if(sData == 1){
				        html = "已屏蔽";
				    }else if(sData == 0){
				        html = "未屏蔽";
				    }else {
				        html ="&nbsp;";
				    }
				    $(nTd).html(html);
				}},
				{"mDataProp":"id","bVisible":false}
			], 
		     "oLanguage": { 
					 				"sZeroRecords": "没有找到记录",
									"sInfo":"",
									"sInfoEmpty": ""
					}
		});
	});	
	function add(){
		window.location.href="${pageContext.request.contextPath}/notify/notify-rule!add.action?resId="+'${resId}';
	}
	function update(id){
		$.ajax({
    		type : "POST",
    		url : "${pageContext.request.contextPath}/notify/notify-rule!checkDeleted.action", //请求的action
    		data : {id:id}, //传的参数
    		dataType : 'json',
    		success : function(data) { //结果
    			if(data.flag == true){
    				window.location.href="${pageContext.request.contextPath}/notify/notify-rule!input.action?resId="+'${resId}'+"&id="+id;
    			}else{
    				getTopWin(window).getMessageBox().alert("此通知规则已经删除","提示");
    				datagrid();
    			}
    		}
    	});
	}
	function view(id){
		$.ajax({
    		type : "POST",
    		url : "${pageContext.request.contextPath}/notify/notify-rule!checkDeleted.action", //请求的action
    		data : {id:id}, //传的参数
    		dataType : 'json',
    		success : function(data) { //结果
    			if(data.flag == true){
    				window.location.href="${pageContext.request.contextPath}/notify/notify-rule!view.action?resId="+'${resId}'+"&id="+id;
    			}else{
    				getTopWin(window).getMessageBox().alert("此通知规则已经删除","提示");
    				datagrid();
    			}
    		}
    	});
	}
	function del(id){
		var submit = function (v, h, f) {
		    if (v == 'ok') {
		    	$.ajax({
		    		type : "POST",
		    		url : "${pageContext.request.contextPath}/notify/notify-rule!delete.action", //请求的action
		    		data : {id:id}, //传的参数
		    		dataType : 'json',
		    		success : function(data) { //结果
		    			if(data == true){
		    				getTopWin(window).getMessageBox().tip('删除事件通知规则成功。', 'success',{timeout: 1500});
							datagrid();
		    			}else{
		    				getTopWin(window).getMessageBox().alert("此通知规则已经删除","提示");
		    				datagrid();
		    			}
		    		}
		    	});
		    }
		    else if (v == 'cancel') {
		    }
		    return true; //close
		};
		getTopWin(window).jBox.confirm("确定要删除数据吗？", "提示", submit);
	}
	
	//禁用
	function disable(id){
		    	$.ajax({
		    		type : "POST",
		    		url : "${pageContext.request.contextPath}/notify/notify-rule!disable.action", //请求的action
		    		data : {id:id}, //传的参数
		    		dataType : 'json',
		    		success : function(data) { //结果
		    			if(data == true){
		    				getTopWin(window).getMessageBox().tip('禁用事件通知规则成功。', 'success',{timeout: 1500});
		    			}else{
		    				getTopWin(window).getMessageBox().alert("此通知规则已经删除","提示");
		    			}
		    			datagrid();
		    		}
		    	});
	}
	
	
    //启用
	function enable(id){
		 $.ajax({
		    type : "POST",
		    url : "${pageContext.request.contextPath}/notify/notify-rule!enable.action", //请求的action
		    data : {id:id}, //传的参数
		    dataType : 'json',
		    success : function(data) { //结果
		    	if(data == true){
		    		getTopWin(window).getMessageBox().tip('启用事件通知规则成功。', 'success',{timeout: 1500});
    			}else{
    				getTopWin(window).getMessageBox().alert("此通知规则已经删除","提示");
    			}
				datagrid();
		    }
		 });
	}
	
	//屏蔽
	function exclude(id,resId){
		    	$.ajax({
		    		type : "POST",
		    		url : "${pageContext.request.contextPath}/notify/notify-rule!exclude.action", //请求的action
		    		data : {id:id,resId:resId}, //传的参数
		    		dataType : 'json',
		    		success : function(data) { //结果
		    			if(data == true){
		    				getTopWin(window).getMessageBox().tip('屏蔽事件通知规则成功。', 'success',{timeout: 1500});
		    			}else{
		    				getTopWin(window).getMessageBox().alert("此通知规则已经删除","提示");
		    			}
						datagrid();
		    		}
		    	});
	}
	
	//解除屏蔽
	function include(id,resId){
		    	$.ajax({
		    		type : "POST",
		    		url : "${pageContext.request.contextPath}/notify/notify-rule!include.action", //请求的action
		    		data : {id:id,resId:resId}, //传的参数
		    		dataType : 'json',
		    		success : function(data) { //结果
		    			if(data == true){
		    				getTopWin(window).getMessageBox().tip('解除屏蔽事件通知规则成功。', 'success',{timeout: 1500});
		    			}else{
		    				getTopWin(window).getMessageBox().alert("此通知规则已经删除","提示");
		    			}
						datagrid();
		    		}
		    	});
	}
	</script>
	<style>
	tr.odd td.sorting_1{
	  width:100px;
	  }	  
	</style>
  </head>
  
  <body>
  <h2 class="title-h2"><span><img src="${pageContext.request.contextPath}/style/default/bsm/images/arrow-down.gif"/></span>事件通知规则列表</h2>
  	<%boolean sysManager = UserFunctionValidate.sysFunctionValidate(FunctionConstants.SYSTEM_MANAGER);%>
	<%if(sysManager){%>
  	<div class="toolbar"  id = "toolbar">
 		<a class="page_add" href="javascript:add();">新增</a>
	</div>
	<%}%>
    <div>
	<table id="depmtList" width="100%" cellpadding="0" cellspacing="0" border="0" class="display">
		<thead>
			<tr >
				<%if(UserFunctionValidate.sysFunctionValidate(FunctionConstants.SYSTEM_MANAGER)){%>
					<th width="120px">操作</th>
				<%}%>	
				<th>规则名称</th>
				<th width="200px">资源名称</th>
				<th width="160px">事件级别</th>
				<th width="80px">当前状态</th>
				<th width="80px">屏蔽状态</th>
			</tr>
		</thead>
	</table>
	</div>
  </body>
</html>